package com.example.site_management_p1.mq;
import com.example.site_management_p1.config.SiteRabbitConfig;
import com.pojo.Entity.VenueRentalForm;
import com.pojo.mapper.DarkRoomMapper;
import com.pojo.mapper.VenueRentalFormMapper;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@RabbitListener(queues = SiteRabbitConfig.DEAD_QUEUE_NAME)
public class ProcessOrder {
        @Autowired
        VenueRentalFormMapper venueRentalFormMapper;
        @Autowired
         DarkRoomMapper darkRoomMapper;
        @RabbitHandler
        public void getReleaseOrderMessage(String message)  {
              Integer vID= Integer.valueOf(message);
              VenueRentalForm venueRentalForm= venueRentalFormMapper.findByvID(vID);
              if(venueRentalForm.getVPaymentStatus()==0){
                      venueRentalFormMapper.update(vID,2);
                      System.out.println(venueRentalForm.getRID());
                      darkRoomMapper.insert(venueRentalForm.getRID(),new Date());
              }
        }
}
